
Public Class SummaryDataReader
    Implements IDataReader

    Private summariesField As New List(Of SummaryDataRecord)
    Private enumeratorField As IEnumerator(Of SummaryDataRecord)

    Private ReadOnly Property Enumerator() As IEnumerator(Of SummaryDataRecord)
        Get
            If Me.enumeratorField Is Nothing Then

                Me.enumeratorField = Me.Summaries.GetEnumerator

            End If

            Return Me.enumeratorField
        End Get
    End Property

    Public Sub New()

    End Sub

    Public Sub New(ByVal records As List(Of SummaryDataRecord))

        Me.summariesField = records

    End Sub

    Public Sub New(ByVal dbName As String, ByVal docSums() As eUtils.DocSumType)

        Dim db As Database = Database.GetDatabase(dbName)

        For Each docSum As eUtils.DocSumType In docSums

            Me.summariesField.Add(db.CreateSummary(docSum))

        Next

    End Sub

    Public Sub New(ByVal dbName As String, ByVal docSums As List(Of eUtils.DocSumType))

        Dim db As Database = Database.GetDatabase(dbName)

        For Each docSum As eUtils.DocSumType In docSums

            Me.summariesField.Add(db.CreateSummary(docSum))

        Next

    End Sub

    Public Sub Import(ByVal reader As SummaryDataReader)

        Me.summariesField.AddRange(reader.Summaries)

    End Sub


#Region "Public Properties"

    Public ReadOnly Property Summaries() As List(Of SummaryDataRecord)
        Get
            Return Me.summariesField
        End Get
    End Property

    Public ReadOnly Property Depth() As Integer Implements System.Data.IDataReader.Depth
        Get
            Return 1
        End Get
    End Property

    Public ReadOnly Property IsClosed() As Boolean Implements System.Data.IDataReader.IsClosed
        Get
            Return Me.Summaries Is Nothing
        End Get
    End Property

    Public ReadOnly Property Current() As SummaryDataRecord
        Get
            Return Me.Enumerator.Current
        End Get
    End Property

    Public ReadOnly Property RecordsAffected() As Integer Implements System.Data.IDataReader.RecordsAffected
        Get
            Return Me.Summaries.Count

        End Get
    End Property

    Public ReadOnly Property FieldCount() As Integer Implements System.Data.IDataRecord.FieldCount
        Get
            Return Me.Current.FieldCount

        End Get
    End Property

    Default Public Overloads ReadOnly Property Item(ByVal i As Integer) As Object Implements System.Data.IDataRecord.Item
        Get
            Return Me.Current.Item(i)
        End Get
    End Property

    Default Public Overloads ReadOnly Property Item(ByVal name As String) As Object Implements System.Data.IDataRecord.Item
        Get

            Return Me.Current.Item(name)

        End Get
    End Property

#End Region

#Region "Public Methods"

    Public Function NextResult() As Boolean Implements System.Data.IDataReader.NextResult
        Return Me.Enumerator.MoveNext
    End Function

    Public Function Read() As Boolean Implements System.Data.IDataReader.Read
        Return Me.Enumerator.MoveNext
    End Function

    Public Function GetSchemaTable() As System.Data.DataTable Implements System.Data.IDataReader.GetSchemaTable
        Return Me.Current.GetSchemaTable
    End Function

    Public Function GetBoolean(ByVal i As Integer) As Boolean Implements System.Data.IDataRecord.GetBoolean
        Return Me.Current.GetBoolean(i)
    End Function

    Public Function GetByte(ByVal i As Integer) As Byte Implements System.Data.IDataRecord.GetByte
        Return Me.Current.GetByte(i)
    End Function

    Public Function GetBytes(ByVal i As Integer, ByVal fieldOffset As Long, ByVal buffer() As Byte, ByVal bufferoffset As Integer, ByVal length As Integer) As Long Implements System.Data.IDataRecord.GetBytes
        Return Me.Current.GetBytes(i, fieldOffset, buffer, bufferoffset, length)
    End Function

    Public Function GetChar(ByVal i As Integer) As Char Implements System.Data.IDataRecord.GetChar
        Return Me.Current.GetChar(i)
    End Function

    Public Function GetChars(ByVal i As Integer, ByVal fieldoffset As Long, ByVal buffer() As Char, ByVal bufferoffset As Integer, ByVal length As Integer) As Long Implements System.Data.IDataRecord.GetChars
        Return Me.Current.GetChars(i, fieldoffset, buffer, bufferoffset, length)
    End Function

    Public Function GetData(ByVal i As Integer) As System.Data.IDataReader Implements System.Data.IDataRecord.GetData
        Return Me.Current.GetData(i)
    End Function

    Public Function GetDataTypeName(ByVal i As Integer) As String Implements System.Data.IDataRecord.GetDataTypeName
        Return Me.Current.GetDataTypeName(i)
    End Function

    Public Function GetDateTime(ByVal i As Integer) As Date Implements System.Data.IDataRecord.GetDateTime
        Return Me.Current.GetDateTime(i)
    End Function

    Public Function GetDecimal(ByVal i As Integer) As Decimal Implements System.Data.IDataRecord.GetDecimal
        Return Me.Current.GetDecimal(i)
    End Function

    Public Function GetDouble(ByVal i As Integer) As Double Implements System.Data.IDataRecord.GetDouble
        Return Me.Current.GetDouble(i)
    End Function

    Public Function GetFieldType(ByVal i As Integer) As System.Type Implements System.Data.IDataRecord.GetFieldType
        Return Me.Current.GetFieldType(i)
    End Function

    Public Function GetFloat(ByVal i As Integer) As Single Implements System.Data.IDataRecord.GetFloat
        Return Me.Current.GetFloat(i)
    End Function

    Public Function GetGuid(ByVal i As Integer) As System.Guid Implements System.Data.IDataRecord.GetGuid
        Return Me.Current.GetGuid(i)
    End Function

    Public Function GetInt16(ByVal i As Integer) As Short Implements System.Data.IDataRecord.GetInt16
        Return Me.Current.GetInt16(i)
    End Function

    Public Function GetInt32(ByVal i As Integer) As Integer Implements System.Data.IDataRecord.GetInt32
        Return Me.Current.GetInt32(i)
    End Function

    Public Function GetInt64(ByVal i As Integer) As Long Implements System.Data.IDataRecord.GetInt64
        Return Me.Current.GetInt64(i)
    End Function

    Public Function GetName(ByVal i As Integer) As String Implements System.Data.IDataRecord.GetName
        Return Me.Current.GetName(i)
    End Function

    Public Function GetOrdinal(ByVal name As String) As Integer Implements System.Data.IDataRecord.GetOrdinal
        Return Me.Current.GetOrdinal(name)
    End Function

    Public Function GetString(ByVal i As Integer) As String Implements System.Data.IDataRecord.GetString
        Return Me.Current.GetString(i)
    End Function

    Public Function GetValue(ByVal i As Integer) As Object Implements System.Data.IDataRecord.GetValue
        Return Me.Current.GetValue(i)
    End Function

    Public Function GetValues(ByVal values() As Object) As Integer Implements System.Data.IDataRecord.GetValues
        Return Me.Current.GetValues(values)
    End Function

    Public Function IsDBNull(ByVal i As Integer) As Boolean Implements System.Data.IDataRecord.IsDBNull
        Return Me.Current.IsDBNull(i)
    End Function

    Public Sub Close() Implements System.Data.IDataReader.Close
        Me.summariesField.Clear()
        Me.summariesField = Nothing
    End Sub

#End Region

#Region " IDisposable Support "
    Private disposedValue As Boolean = False        ' To detect redundant calls

    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then

                Me.Close()

            End If

            ' TODO: free shared unmanaged resources
        End If
        Me.disposedValue = True
    End Sub


    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub


#End Region


End Class
